﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KeMei.Common;

public partial class Manager_ChangePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserInfo"] == null)
        {
            Response.Redirect("login.aspx", true);

        }
        if (!IsPostBack)
        {
            InitModel((int)Session["UserID"]);
        }
    }

    /// <summary>
    /// 绑定实体类到控件
    /// </summary>
    protected void InitModel(int ID)
    {
        KeMei.Model.SysUser model = null;
        KeMei.BLL.SysUser bll = new KeMei.BLL.SysUser();

        try
        {
            model = bll.GetModel(ID);

            if (model != null)
            {
                
                txtName.Text = model.TName;
            }
        }
        catch (Exception ex)
        {

            ExtAspNet.Alert.Show("初始化实体类失败：" + ex.Message);
        }
    }


   



    /// <summary>
    /// 保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        KeMei.BLL.SysUser bll = new KeMei.BLL.SysUser();

        try
        {
            KeMei.Model.SysUser model = (KeMei.Model.SysUser)Session["UserInfo"];

            if (model.Password !=DESEncrypt.Encrypt(txtPwd1.Text.Trim()))
            {
                ExtAspNet.Alert.Show("原密码错误");
                return;
            }

            model.Password =DESEncrypt.Encrypt( txtPwd3.Text);

            bll.Update(model);

            ExtAspNet.Alert.Show("修改成功！", String.Empty, ExtAspNet.Alert.DefaultIcon, ExtAspNet.ActiveWindow.GetHideReference());
        }
        catch (Exception ex)
        {
            ExtAspNet.Alert.Show("保存失败：" + ex.Message);
        }
    }
}